package com.order.api.controller;

import com.order.api.service.ShopsService;
import com.order.api.target.Authorization;
import com.order.api.target.MethodLog;
import com.order.api.vo.BaseResult;
import com.order.api.vo.request.ShopsAddRequest;
import com.order.api.vo.request.ShopsIdRequest;
import com.order.api.vo.request.ShopsUpdateRequest;
import com.order.api.vo.response.ShopsResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "商品模块")
@RestController
@RequestMapping("/shops")
public class ShopsController {

    @Autowired
    private ShopsService shopsService;

    @Authorization
    @ApiOperation("商品列表-不分页")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @MethodLog(optType = "商品列表-不分页",systemModel = "商品模块")
    public BaseResult<List<ShopsResponse>> shopList(){
        return BaseResult.success(shopsService.findShops());
    }

    @Authorization
    @ApiOperation("商品详情")
    @RequestMapping(value = "/detail",method = RequestMethod.POST)
    @MethodLog(optType = "商品详情",systemModel = "商品模块")
    public BaseResult<ShopsResponse> findDetail(@RequestBody ShopsIdRequest request){
        return BaseResult.success(shopsService.findDetail(request));
    }

    @Authorization
    @ApiOperation("商品添加")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @MethodLog(optType = "商品添加",systemModel = "商品模块")
    public BaseResult<String> addShop(@RequestBody ShopsAddRequest request){
        return BaseResult.judgeOperate(shopsService.addShops(request));
    }

    @Authorization
    @ApiOperation("商品信息修改")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @MethodLog(optType = "商品信息修改",systemModel = "商品模块")
    public BaseResult<String> updateShop(@RequestBody ShopsUpdateRequest request){
        return BaseResult.judgeOperate(shopsService.updateShops(request));
    }

    @Authorization
    @ApiOperation("商品删除")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @MethodLog(optType = "商品删除",systemModel = "商品模块")
    public BaseResult<String> deleteShops(@RequestBody ShopsIdRequest request){
        return BaseResult.judgeOperate(shopsService.deleteShops(request));
    }
}
